﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using PMS.IServices;
using PMS.Models.Base;
using PMS.Services;
using PMS.Utils;

namespace PMS.EasyUI.Areas.Base.Controllers
{
    public class BaseUserController : Controller
    {
        IBaseUserService _baseUserService = new BaseUserService();
        // GET: Base/BaseUser
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Edit(int Id)
        {
            BaseUser user = _baseUserService.Dtl(Id);
            return View(user);
        }

        [HttpPost]
        public ActionResult Edit(BaseUser user)
        {
            user.UpdateDate = DateTime.Now;
            user.UpdateBy = 999;
            if (_baseUserService.Edit(user) > 0)
            {
                return Json(Result.Success, "text/html", JsonRequestBehavior.AllowGet);
            }

            return Json(Result.Error, "text/html", JsonRequestBehavior.AllowGet);
        }

        [HttpPost]
        public ActionResult Delete(int Id)
        {
            if (_baseUserService.Delete(Id, "1") > 0)
            {
                return Json(Result.Success, "text/html", JsonRequestBehavior.AllowGet);
            }

            return Json(Result.Error, "text/html", JsonRequestBehavior.AllowGet);
        }

        public ActionResult GetList()
        {
            int counts = 0;
            int pageIndex = Request.Form["page"].ToInt32();
            int pageSize = Request.Form["rows"].ToInt32();
            var data = _baseUserService.GetList(new Hashtable(), "Id", "Desc", pageIndex, pageSize, out counts);
            return Json(new { total = counts, rows = data }, "text/html", JsonRequestBehavior.AllowGet);
        }
    }
}